Date.prototype.Format = function(fmt) {
    var o = {
        "M+": this.getMonth() + 1,
        "d+": this.getDate(),
        "h+": this.getHours(),
        "m+": this.getMinutes(),
        "s+": this.getSeconds(),
        "q+": Math.floor((this.getMonth() + 3) / 3),
        "S": this.getMilliseconds()
    };
    if (/(y+)/.test(fmt)) fmt = fmt.replace(RegExp.$1, (this.getFullYear() + "").substr(4 - RegExp.$1.length));
    for (var k in o) if (new RegExp("(" + k + ")").test(fmt)) fmt = fmt.replace(RegExp.$1, (RegExp.$1.length == 1) ? (o[k]) : (("00" + o[k]).substr(("" + o[k]).length)));
    return fmt
};
var IyBaseData={
    data:{
        tabHome_tab:0
    }
};
var IyBaseFun={
    e:{
        $Body:$('body')
    },
    i:function(){
        this.tab();
    },
    tab:function(){//tab切换
        this.e.$Body.on('click','[data-toggle="tab"]',function(){
           var t=$(this),role=t.attr('role'),ta=t.parent('.iy-tab-nav'),i=ta.index();
           if(!ta.hasClass('active')){
               ta.addClass('active').siblings().removeClass('active');
               IyBaseData.data[role+"_tab"]=i;
               $('.iy-tab-pane[role="'+role+'"]').eq(i).addClass('active').siblings().removeClass('active');
               if(!cyb.init.d['loadTab'+i+'End']){
                   cyb.init.d.$touch.unlock();//解锁
                   cyb.init.d.$touch.noData(false);
               }else{
                   cyb.init.d.$touch.lock('down');//锁
                   cyb.init.d.$touch.noData();
               }
               cyb.init.d.$touch.resetload();
           }
        });
    }
};
IyBaseFun.i();

Date.prototype.Format = function(fmt) {
    var o = {
        "M+": this.getMonth() + 1,
        "d+": this.getDate(),
        "h+": this.getHours(),
        "m+": this.getMinutes(),
        "s+": this.getSeconds(),
        "q+": Math.floor((this.getMonth() + 3) / 3),
        "S": this.getMilliseconds()
    };
    if (/(y+)/.test(fmt)) fmt = fmt.replace(RegExp.$1, (this.getFullYear() + "").substr(4 - RegExp.$1.length));
    for (var k in o) if (new RegExp("(" + k + ")").test(fmt)) fmt = fmt.replace(RegExp.$1, (RegExp.$1.length == 1) ? (o[k]) : (("00" + o[k]).substr(("" + o[k]).length)));
    return fmt
};
var loading={
    init:function(box,isPage){
        var $loading = $("<div/>").addClass("ball-spin-fade-loader");
        for (var i = 0; i < 8; i++) {
            $("<div/>").appendTo($loading)
        }
        if(isPage){
            box.prepend($loading)
        }else{
            var $Div=$("<div/>").addClass("loadDiv").append($loading).appendTo(box);
        }
    }
};
var comNotice = {
    init: function(txt, isLoading, time) {
        this.close();
        var $notice = $("<div/>").addClass("mod-notice").appendTo("body");
        $("<p/>").text(txt).appendTo($notice);
        if (isLoading) {
            loading.init($notice,true);
        }
        var tm = time * 1000 || 2000;
        setTimeout(function() {
            $notice.remove()
        },tm)
    },
    close: function() {
        $(".mod-notice").remove()
    }
};

var comSelect={
    d:{
        l:0,//几级
        d2:[],//联动数据->二级
        d3:[],//联动数据->三级
        as:false//是否联动->默认关闭
    },
    init:function(data,cname){
        var body=$("body");
        if(data[0]==undefined||data[0]=="") return;
        comSelect.d.d2=comSelect.d.d3=[];
        $("html").css("overflow","hidden");
        var mselect=$("<div/>").addClass("mod-select").appendTo(body);
        $("<div/>").addClass("ms-mark").appendTo(mselect);
        var box=$("<div/>").addClass("ms-box").appendTo(mselect),
            hd=$("<div/>").addClass("ms-hd").append('<a href="javascript:;" class="btn btn-ms-sure" data-bclick="'+cname+'">确定</a><a href="javascript:;" class="btn btn-ms-cancel">取消</a>').appendTo(box),
            bd=$("<div/>").addClass("ms-bd").appendTo(box),
            wrap=$("<div/>").addClass("ms-wrap").appendTo(bd);
        if(undefined!= (data[0].name)&&(data[0].name!="")){
            comSelect.d.as=true;
            var l1=data.length;
            //一级
            var mod1=$("<div/>").addClass("ms-mod").appendTo(wrap),
                ol1=$("<ol/>").css("top",35).appendTo(mod1);
            for(var i=0;i<l1;i++){
                var $li1 = $("<li/>").append(data[i].name).appendTo(ol1);
                if(i==0){$li1.addClass("active")}
            }
            if("object"===typeof (data[0].con[0])){
                //三级
                comSelect.d.l=3;
                var Mod32=$("<div/>").addClass("ms-mod").appendTo(wrap),
                    ol32=$("<ol/>").css("top",35).appendTo(Mod32);
                var l32=data[0].con.length;
                for(var i32=0;i32<l32;i32++){
                    var $li2 = $("<li/>").append(data[0].con[i32].name).appendTo(ol32);
                    if(i32==0){$li2.addClass("active")}
                }
                var Mod33=$("<div/>").addClass("ms-mod").appendTo(wrap),
                    ol33=$("<ol/>").css("top",35).appendTo(Mod33);
                this.o(data[0].con[0].con,ol33);
                this.f(data,comSelect.d.d2,comSelect.d.d3);
            }else{
                //二级
                comSelect.d.l=2;
                var Mod2=$("<div/>").addClass("ms-mod").appendTo(wrap),
                    ol2=$("<ol/>").css("top",35).appendTo(Mod2);
                this.o(data[0].con,ol2);
                this.s(data,comSelect.d.d2);
            }
        }else{
            comSelect.d.l=data.length;
            for(var si=0;si<comSelect.d.l;si++){
                var sMod=$("<div/>").addClass("ms-mod").appendTo(wrap),
                    sOl=$("<ol/>").css("top",35).appendTo(sMod);
                this.o(data[si],sOl);
            }
        }
        wrap.addClass("ms-"+comSelect.d.l);
        this.close();
        setTimeout(function(){
            $(".mod-select").addClass("show");
        },10);
        selectBase.d.my=''//重置旧的
    },
    minS:function(data,sName){
        var body=$("body");
        $("html").css("overflow","hidden");
        var mselect=$("<div/>").addClass("mod-select "+sName).appendTo(body);
        $("<div/>").addClass("ms-mark").appendTo(mselect);
        var box=$("<div/>").addClass("ms-box").appendTo(mselect),
            bd=$("<div/>").addClass("ms-min").appendTo(box),
            Ul=$("<ul/>").appendTo(bd),
            ft=$("<div/>").addClass("ms-ft").append('<a href="javascript:;" class="btn btn-ms-cancel">取消</a>').appendTo(box);
        for(var mi=0;mi<data.length;mi++){
            var li=$("<li/>").append(data[mi]).appendTo(Ul);
        }
        this.close();
        setTimeout(function(){
            $(".mod-select").addClass("show");
        },10);
    },
    o:function(s,b){
        if(s==""||s==undefined){
            b.append('<li class="active">--</li>');
            return;
        }
        for(var i=0;i< s.length;i++){
            var $l=$("<li/>").append(s[i]).appendTo(b);
            if(i==0){
                $l.addClass("active");
            }
        }
    },
    s:function(s,b){
        for(var i=0;i< s.length;i++){
            b.push(s[i].con);
        }
    },
    f:function(s,b2,b3){
        for(var i=0;i< s.length;i++){
            var m=[],n=[];
            for(var j=0;j<s[i].con.length;j++){
                m.push(s[i].con[j].con);
                n.push(s[i].con[j].name);
            }
            b2.push(n);
            b3.push(m);
        }
    },
    m:function(w,m){
        if(comSelect.d.as&&w<comSelect.d.l){
            var wrap=$(".ms-wrap");
            if(comSelect.d.l==2){
                var b=wrap.find(".ms-mod").eq(1),
                    ol=$("<ol/>").css("top",35);
                b.empty().append(ol);
                this.o(comSelect.d.d2[m],ol);
            }else if(comSelect.d.l==3){
                var i=wrap.find(".ms-mod").eq(0).find(".active").index();
                if(w==2){
                    var b2=wrap.find(".ms-mod").eq(w),
                        ol2=$("<ol/>").css("top",35);
                    b2.empty().append(ol2);
                    this.o(comSelect.d.d3[i][m],ol2);
                }else if(w==1){
                    var b32=wrap.find(".ms-mod").eq(w),
                        o32=$("<ol/>").css("top",35),
                        b33=wrap.find(".ms-mod").eq(w+1),
                        o33=$("<ol/>").css("top",35);
                    b32.empty().append(o32);
                    b33.empty().append(o33);
                    this.o(comSelect.d.d2[i],o32);
                    this.o(comSelect.d.d3[i][0],o33);
                }
            }
        }
    },
    close:function(){
        var body=$("body");
        body.on("click",".btn-ms-cancel",function(){
            var select=$(".mod-select");
            select.removeClass("show");
            setTimeout(function(){
                select.remove();
                $("html").attr("style","");
            },500);
        });
        body.on('click','.ms-mark',function(){
            $('.btn-ms-cancel').click();
        });
    },
    t:function(y,cname){
        var data=[],dy=[];
        var time=new Date(),
            ny=time.getFullYear();
        for(var i=y;i<ny+1;i++){
            dy.push(i);
        }
        var dm=["01","02","03","04","05","06","07","08","09","10","11","12"];
        data.push(dy,dm);
        this.init(data,cname);
    }
};

var selectBase={
    d:{
        my:''
    },
    init:function(){
        this.mc();
    },
    mc:function(){
        var body=$("body");
        var oldY=0;
        var ox,oy,nx,ny,xw,yh,cx,cy;
        body.on("touchstart",".ms-mod ol",function(e) {
            $(this).removeClass("ms-move");
            ox = e.originalEvent.changedTouches[0].pageX;
            oy = e.originalEvent.changedTouches[0].pageY;
        });
        body.on("touchmove",".ms-mod ol",function(e) {
            e.preventDefault();
            var that=$(this);
            nx = e.originalEvent.changedTouches[0].pageX;
            ny = e.originalEvent.changedTouches[0].pageY;
            cx = nx - ox;
            cy = ny - oy;
            xw = Math.abs(cx);
            yh = Math.abs(cy);

            var idx=that.find(".active").index();
            oldY=-idx*35;
            if (xw < yh) {
                selectBase.d.my=oldY+cy;
                var maxY=that.height();
                if(selectBase.d.my<-maxY){
                    selectBase.d.my=-maxY
                }
                that.css("transform","translateY("+ selectBase.d.my +"px)")
            }
        });
        body.on("touchend",".ms-mod ol",function(){
            var that=$(this);
            var n=Math.floor(selectBase.d.my/35);
            var v=(selectBase.d.my%35)/35;
            if(n>=0) n=0;
            if(n<0&&v>-0.5){
                n=n+1;
            }
            var m=Math.abs(n);
            var moveY=0;
            if(m*35==that.height()){
                moveY=(n+1)*35;
                m=m-1;
            }else{
                moveY=n*35
            }
            that.addClass("ms-move").css("transform","translateY("+ moveY +"px)");
            that.find("li").eq(m).addClass("active").siblings().removeClass("active");
            if(oldY!=moveY){
                comSelect.m(that.parent(".ms-mod").index()+1,m);
            }
        });
    },
    pc:function(){
        var body=$("body");
        var oldY=0;
        var oX,mX,oY,mY,nH,nW,my,lock=0;
        body.on("mousedown",".ms-mod ol",function(e){
            lock=1;
            oY=e.originalEvent.pageY;
            oX=e.originalEvent.pageX;
            $(this).addClass("msMove")
        }).on("mousemove",function(e){
            var that=$(".msMove");
            if(lock){
                mY=e.originalEvent.pageY;
                mX=e.originalEvent.pageX;
                nH=mY-oY;
                nW=mX-oX;
                var idx=that.find(".active").index();
                oldY=-idx*35;
                if(Math.abs(nH)>Math.abs(nW)){
                    my=oldY+nH;
                    var maxY=that.height();
                    if(my<-maxY){
                        my=-maxY
                    }
                    that.css("transform","translateY("+ my +"px)")
                }
                clear();
            }
        }).on("mouseup",function(){
            lock=0;
            if(body.find(".msMove").length>0){
                var that=$(".msMove");
                var n=Math.floor(my/35);
                var v=(my%35)/35;
                if(n>=0) n=0;
                if(n<0&&v>-0.5){
                    n=n+1;
                }
                var m=Math.abs(n);
                var moveY=0;
                if(m*35==that.height()){
                    moveY=(n+1)*35;
                    m=m-1;
                }else{
                    moveY=n*35
                }
                that.find("li").eq(m).addClass("active").siblings().removeClass("active");
                if(oldY!=moveY){
                    if(that.parent(".ms-mod").index()+1<comSelect.d.l){
                        comSelect.m(that.parent(".ms-mod").index()+1,m);
                    }
                }
                that.removeClass("msMove").css("transform","translateY("+ moveY +"px)");
            }
        });
        function clear(){
            //清除文本选中状态
            if(document.selection&&document.selection.empty){
                document.selection.empty();//IE
            }else if(window.getSelection){
                window.getSelection().removeAllRanges();
            }
        }
    }
};
selectBase.init();

var Iy={

    isHttp : function(str){
        var http=/^(https?|ftp|file):\/\//;
        if(!http.test(str)){
            str='http://'+str
        }
        return str;
    },
    isIp:function (ip) {
        var reg = /^(\d{1,2}|1\d\d|2[0-4]\d|25[0-5])\.(\d{1,2}|1\d\d|2[0-4]\d|25[0-5])\.(\d{1,2}|1\d\d|2[0-4]\d|25[0-5])\.(\d{1,2}|1\d\d|2[0-4]\d|25[0-5])$/;
        return reg.test(ip);
    },
    isYm:function(ym){
        return /[a-zA-Z0-9][-a-zA-Z0-9]{0,62}(\.[a-zA-Z0-9][-a-zA-Z0-9]{0,62})+\.?/.test(ym);
    },
    isUrl:function(url){
        return /^(https?|ftp|files):\/\/[A-Za-z0-9-_]+\.[A-Za-z0-9]+[\/=\?%\-&_~`@[\]\':+!]*([^<>\"\"])*$/.test(url);
    },
    isFax:function(fax){
        return /^(\d{3,4}-)?\d{7,8}$/.test(fax)
    }
};

//获取地址栏参数
var getUrlParam = {
    init: function() {
        var search = window.location.search;
        if(search==''){
            search=window.location.hash.split('?');
            if(search.length>1){
                search='?'+search[1]
            }else{
                search=''
            }
        }
        search = unescape(search);
        var tmparray = search.substr(1, search.length).split("&");
        var paramsArray = new Array;
        if (tmparray != null) {
            for (var i = 0; i < tmparray.length; i++) {
                var reg = /[=|^==]/;
                var set1 = tmparray[i].replace(reg, '&');
                var tmpStr2 = set1.split('&');
                var array = new Array;
                array[tmpStr2[0]] = tmpStr2[1];
                paramsArray.push(array)
            }
        }
        return paramsArray
    },
    get: function(param) {
        var paramsArray = this.init();
        if (paramsArray != null) {
            for (var i = 0; i < paramsArray.length; i++) {
                for (var j in paramsArray[i]) {
                    if (j == param) {
                        return paramsArray[i][j]
                    }
                }
            }
        }
        return null
    }
};
